package com.johndriver.selenium.explorer;

import com.johndriver.selenium.driver.DriverDemo;
import lombok.extern.slf4j.Slf4j;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

import java.sql.Driver;

/**
 * 浏览器操作
 * 日期 2021/5/22 16:50
 * 创建者：john driver
 */
@Slf4j
public class BrowserManipulation {
    public static void main(String[] args) {
        final WebDriver driver = DriverDemo.driver();
        //navigation(driver);
        driver.get("https://www.duquanben.com/");
        // 2.视窗和分页
        //获取当前窗口句柄
        String originalWindow = driver.getWindowHandle();
        log.info(originalWindow);

        //
        final WebElement a = driver.findElement(new By.ByCssSelector("div.hot-data > div.hot-img > a"));
        a.click();
        final String windowHandle = driver.getWindowHandle();
        driver.switchTo();
        driver.quit();
    }

    private static void navigation(WebDriver driver) {
        //1.浏览器导航导航，打开网站
        driver.get("https://www.duquanben.com/");//driver.navigate().to("https://selenium.dev");
        //获取当前URL 标题
        log.info(driver.getCurrentUrl());
        log.info(driver.getTitle());
        //后退 前进 刷新当前页
        driver.navigate().back();
        driver.navigate().forward();
        driver.navigate().refresh();
    }
}
